using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.Material;
using ProduceBasicData.Api.Application.Command.Material.Craft;
using ProduceBasicData.Api.Application.Command.Material.GroupType;
using ProduceBasicData.Api.Application.Command.Material.MaterialGroup;
using ProduceBasicData.Api.Application.Command.Material.MaterialType;
using ProduceBasicData.Api.DTO;
using ProduceBasicData.ErrorCode;

namespace ProduceBasicData.Api.Controllers.Material
{
    /// <summary>
    /// 物料群组控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaterialController : ControllerBase
    {
        private readonly IMediator mediator;

        public MaterialController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 查询物料群组信息接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<MaterialGroupDTO>> GetMaterial([FromQuery]GetMaterialGroupCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 物料群组信息录入接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateMaterial(CreateMaterialGroupCommand request)
        {
            return await mediator.Send(request);    
        }

        /// <summary>
        /// 群组类型查询接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<GroupTypeDTO>>> GetGroupType([FromQuery]GetGroupTypeCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 物料类型查询接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<MaterialTypeDTO>>> GetMaterialType([FromQuery]GetMaterialTypeCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 物料修改接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateMaterial(UpdateMaterialGroupCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 批量删除物料接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DelRangeMaterial(DeleteRangeMaterialGroupCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 单个删除物料接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteMaterial(DeleteMaterialGroupCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 获取工艺路线列表处理器
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<CraftDTO>> GetCraftList([FromQuery]GetCraftListCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 工艺路线选择接口（用于下拉框）
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<CraftSelectDTO>>> GetCraftSelect([FromQuery]GetCraftSelectCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 新增工艺路线
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateCraft(CreateCraftCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 更新工艺路线
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateCraft(UpdateCraftCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 删除工艺路线
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult<int>> DeleteCraft([FromQuery]DeleteCraftCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 获取物料下拉框数据
        /// </summary>
        /// <returns>物料列表</returns>
        [HttpGet]
        public async Task<ApiResult<List<Domain.Material.ProductMaterialModel>>> GetMaterialDropdown()
        {
            GetMaterialDropdownCommand request = new GetMaterialDropdownCommand();
            return await mediator.Send(request);
        }

    }
}
